<?php
$rows = array( array('需求单号:', $summary['demands']) );

$rows[] = array('材料编号','材料名称','品牌','规格','单位',
				'补库数量','单价','金额',
				'专项数量','单价','金额',
				'紧急数量','单价','金额',
				'小计数量','单价','金额',
				'部门','备注');

if($summary['items']){
    $bc=0;$bcm=0;$zc=0;$zcm=0;$jc=0;$jcm=0;$tc=0;$tcm=0;
	foreach($summary['items'] as $ware){
		foreach($ware['list'] as $dept){
			
			$tmp = array( $ware['sno'], $ware['name'], $ware['brand'], $ware['specific'], $ware['unit'] );
			
			$tmp[] = $dept[0]['amount'];
			if($dept[0]['amount'] && floatval($ware['price'])){
				$tmp[] = fnum($ware['price']);
				$tmp[] = fnum($ware['price']*$dept[0]['amount']);
                                $bc += $dept[0]['amount'];$bcm += fnum($ware['price']*$dept[0]['amount']);
			}
			else{
				$tmp[] = '';
				$tmp[] = '';
			}
			
			$tmp[] = $dept[1]['amount'];
			if($dept[1]['amount'] && floatval($ware['price'])){
				$tmp[] = fnum($ware['price']);
				$tmp[] = fnum($ware['price']*$dept[1]['amount']);
                                $zc += $dept[1]['amount'];$zcm += fnum($ware['price']*$dept[1]['amount']);
			}
			else{
				$tmp[] = '';
				$tmp[] = '';
			}
			
			$tmp[] = $dept[2]['amount'];
			if($dept[2]['amount'] && floatval($ware['price'])){
				$tmp[] = fnum($ware['price']);
				$tmp[] = fnum($ware['price']*$dept[2]['amount']);
                                $jc += $dept[2]['amount'];$jcm += fnum($ware['price']*$dept[2]['amount']);
			}
			else{
				$tmp[] = '';
				$tmp[] = '';
			}
			
			$tmp[] = $ware['amount'];
			$tmp[] = fnum($ware['price']);
			$tmp[] = fnum($ware['total']);
                        $tc += fnum($ware['price']);$tcm += fnum($ware['total']);
			$tmp[] = $dept['name'];
			$tmp[] = $dept['remark'];
			
			$rows[] = $tmp;
		}
	}
        $rows[] = array('合计','','','','',
				$bc,'',$bcm,
				$zc,'',$zcm,
				$jc,'',$jcm,
				$tc,'',$tcm,
				'','');
}

Exporter::csv($rows, "采购需求汇总表-".fetch_a_int('id'));

?>
